package routers

import (
	"dc-news/common/global/setting"
	"dc-news/common/middleware/cros"
	"github.com/gin-contrib/zap"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
	"time"
)

func SetupRouter() *gin.Engine {
	r := gin.New()
	r.Use(cros.Cors())
	if setting.Conf.Release {
		gin.SetMode(gin.ReleaseMode)
	}
	r.Use(ginzap.Ginzap(zap.L(), time.RFC3339, false))
	r.Use(ginzap.RecoveryWithZap(zap.L(), true))
	r.GET("", func(c *gin.Context) {
		c.String(http.StatusOK, "dc-news api is running...")
	})
	SetupUserRouter(r)
	SetupNewsRouter(r)
	SetupCommentRouter(r)
	return r
}
